<?php
class UserModel extends Zend_Db_Table_Abstract
{
	protected $_name = 'taikhoan';
	protected $_primary = 'id';

	//dua ra danh sach user
	public function getListUser($value = NULL) {
		$db = Zend_Registry::get('connectDB');
		$query = $db->select()
					->from($this->_name);
		if(isset($value)){
			$query->where('quyenHan=?',$value);
		}
		$list = $db->fetchAll($query);
		return $list;
	}


	/**
	* Kiem tra xem co trong danh sach hay khong tra ve quyen han
	*/
	public function checkUserLogin($username, $password) {
		$db = Zend_Registry::get('connectDB');
		$query = $db->select()
					->from($this->_name)
					->where('tenTK=?', $username);
		$result = $db->fetchRow($query);
		
		if(!empty($result)) { //neu co ket qua thi so sanh mat khau
			$passwordResult = $result['matKhau'];
			if ($password == $passwordResult)
				return $result['quyenHan'];
		}
		return false;
	}

	/**
	* Lay thong tin cua mot user
	*/
	public function getUserInfoByName($username) {
		$db = Zend_Registry::get('connectDB');
		$query = $db->select()
					->from($this->_name)
					->where('tenTK=?', $username);
		$result = $db->fetchRow($query);
		return $result;
	}
}
?>